package com.yami.shop.multishop.controller;

import com.yami.shop.bean.model.ShopPayAppSetting;
import com.yami.shop.service.ShopPayAppSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 店铺支付宝支付设置Controller
 */
@RestController
@RequestMapping("/shop/pay/appsetting")
@Api(tags = "店铺支付宝支付设置接口")
@Slf4j
public class ShopPayAppSettingController {

    @Autowired
    private ShopPayAppSettingService shopPayAppSettingService;

    @GetMapping("/info")
    @ApiOperation(value = "获取店铺支付宝支付设置")
    public ResponseEntity<ShopPayAppSetting> getShopPayAppSetting(@ApiParam("店铺ID") @RequestParam Long shopId) {
        try {
            ShopPayAppSetting shopPayAppSetting = shopPayAppSettingService.getShopPayAppSetting(shopId);
            return ResponseEntity.ok(shopPayAppSetting);
        } catch (Exception e) {
            log.error("获取店铺支付宝支付设置失败", e);
            return ResponseEntity.badRequest().build();
        }
    }

    @PostMapping("/update")
    @ApiOperation(value = "更新店铺支付宝支付设置")
    public ResponseEntity<Void> updateShopPayAppSetting(@Valid @RequestBody ShopPayAppSetting shopPayAppSetting) {
        try {
            shopPayAppSettingService.updateShopPayAppSetting(shopPayAppSetting);
            return ResponseEntity.ok().build();
        } catch (Exception e) {
            log.error("更新店铺支付宝支付设置失败", e);
            return ResponseEntity.badRequest().build();
        }
    }

    @PostMapping("/update-withdrawal-method")
    @ApiOperation(value = "更新提现方式")
    public ResponseEntity<Void> updateWithdrawalMethod(
            @ApiParam("店铺ID") @RequestParam Long shopId,
            @ApiParam("提现方式（0-手动 1-自动）") @RequestParam Integer withdrawalMethod) {
        try {
            shopPayAppSettingService.updateWithdrawalMethod(shopId, withdrawalMethod);
            return ResponseEntity.ok().build();
        } catch (Exception e) {
            log.error("更新提现方式失败", e);
            return ResponseEntity.badRequest().build();
        }
    }
} 